import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);

// 数据
const state={
    usermes: {
        // count: '2',
        jifen: '',    //现金积分
        bi: '',       //EBUC币
        zhucebi: '',  //注册币
        jihuoma: '',  //激活码
        name: '',     //用户名
        grade: '',    //等级
        baodan: '',   //报单状态(2报单上级，1普通)
        uid: '',      //用户id
        money: ''
    },
    isactive1: ''     // isactive1状态
}

// mutations方法
const mutations={
    add(state){
        state.count++;
    },
    reduce(state){
        state.count--;
    },
    // isactive1状态
    // activeStatus (state, status) {
    //     state.isactive1 = status
    // },
    // 接收存入的值
    increment (state, payload) {
        state.usermes.jifen = payload.jifen,
        state.usermes.bi = payload.bi,
        state.usermes.zhucebi = payload.zhucebi,
        state.usermes.jihuoma = payload.jihuoma,
        state.usermes.name = payload.name,
        state.usermes.grade = payload.grade,
        state.usermes.baodan = payload.baodan,
        state.usermes.uid = payload.uid,
        state.usermes.money = payload.money
    },
    // 转化时间
    // times (value) {         
    //   var time = this.value;
    //   var timeTo = new Date(time);
    //   var times=timeTo.getFullYear() + '-' + (timeTo.getMonth() + 1) + '-' + timeTo.getDate() + ' ' + timeTo.getHours() + ':' + timeTo.getMinutes() + ':' + timeTo.getSeconds();
    //   return times;
    // },
    //登入，保存状态
    addLogin (state) {
        // console.log();
        sessionStorage.setItem("usermes", JSON.stringify(state));  //添加到sessionStorage
        state.usermes=state.usermes            //同步的改变store中的状态
    }, 
    //退出，删除状态
    signOut (state) {
        sessionStorage.removeItem("usermes");  //移除sessionStorage
        sessionStorage.removeItem("isLogin");
        // state.username=''                //同步的改变story中的状态
        state.isLogin=false
    }


    
}

// getters方法
const getters = {
}

// actions方法
const actions ={
}

export default new Vuex.Store({
	state,mutations,getters,actions
})